<?php

namespace App\V3\V3_1\Services;

use App\V3\V3_1\Models\TallyClassModel;

class TallyClassService
{
    //列表
    static public function index($mainId)
    {
        return TallyClassModel::select(
            'id', 'name'
        )->with('children', function($query) {
            $query->select(
                'id', 'name', 'parent_id'
            )->orderBy('id', 'DESC');
        })->where('parent_id', 0)
        ->where('main_id', $mainId)
        ->orderBy('id', 'DESC')
        ->get();
    }

    //检查记账类型
    static public function checkTallyClass($data)
    {
        if(empty(TallyClassModel::where($data)->first())) {
            return true;
        }
        else {
            return false;
        }
    }
}
